package cn.edu.scau.cmi.xuminbang.client.classicsDesignPattern;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.Scanner;

import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.context.ApplicationContext;

import com.sun.accessibility.internal.resources.accessibility;
import com.sun.corba.se.spi.orbutil.fsm.State;
import cn.edu.scau.cmi.xuminbang.abstractFactory.AbstractFactory;
import cn.edu.scau.cmi.xuminbang.abstractFactory.AonongFactory;
import cn.edu.scau.cmi.xuminbang.abstractFactory.TianbangFactory;
import cn.edu.scau.cmi.xuminbang.abstractFactory.WensFactory;
import cn.edu.scau.cmi.xuminbang.adapter.Students;
import cn.edu.scau.cmi.xuminbang.client.hibernate.HibernateClientHibernateDao;
import cn.edu.scau.cmi.xuminbang.client.spring.Spring03SingletonApplicationContextClient;
import cn.edu.scau.cmi.xuminbang.adapter.AdapterStudent;
import cn.edu.scau.cmi.xuminbang.factory.BeefMeatFactory;
import cn.edu.scau.cmi.xuminbang.factory.ChickenMeatFactory;
import cn.edu.scau.cmi.xuminbang.factory.PorkMeatFactory;
import cn.edu.scau.cmi.xuminbang.factory.MeatFactory;
import cn.edu.scau.cmi.xuminbang.interProgramming.GraduateStudent;
import cn.edu.scau.cmi.xuminbang.interProgramming.Student;
import cn.edu.scau.cmi.xuminbang.interProgramming.UndergraduateStudent;
import cn.edu.scau.cmi.xuminbang.simpleFactoryMethon.Meat;
import cn.edu.scau.cmi.xuminbang.simpleFactoryMethon.SimpleMeatFactory;
import cn.edu.scau.cmi.xuminbang.spring.domain.IocStudent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class ControlerForComprehensiveExperiment implements Initializable{

	@FXML Button singletonPattern;
	@FXML Button epBase;
	@FXML Button simpleFactory;
	@FXML Button factory;
	@FXML Button abstractFactory;
	@FXML Button adapter;
	@FXML Button consistentComposite;
	@FXML Button safeComposite;
	@FXML Button hibernate;
	@FXML Button useOfSpring;
	@FXML ImageView imageView;
	@FXML Label warn;




	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		
	}
	public ControlerForComprehensiveExperiment () {
		
	}
	public void singletonPattern() {//实验二
		Stage stage = new Stage();
        try{
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass().getResource("SingletonClient.fxml"));
            Parent root = (Parent)loader.load();
            Scene scene = new Scene(root);
            stage.setTitle("Singleton");
            stage.setScene(scene);
            stage.show();
        }catch (Exception e){
            e.printStackTrace();
        }
	}
	public void epBase() {//实验一
		Student student1= new GraduateStudent();
		Student student2= new UndergraduateStudent();
		student1.learning();
		student2.learning();//在控制台输出
		TextField testField = new TextField();
		testField.setText("好好学习天天向上;996编码\n007做科研");
		Stage stage1 = new Stage();
		StackPane layout = new StackPane();
		layout.getChildren().add(testField);
		Scene scene = new Scene(layout,300,300);
		stage1.setScene(scene);
		stage1.setTitle("实验一 实验基础");
		stage1.show();
	}
	public void simpleFactory() {
		String nameOfMeat;
		System.out.print("please select the meat you want,chicken,beef or pork?\n");
		nameOfMeat =ComprehensiveExperimentClient.scanner.nextLine();
		SimpleMeatFactory meatFactory = new SimpleMeatFactory();
		meatFactory.productMeat(nameOfMeat);
	}
	public void factoryPattern() {
		System.out.println("Please select which kind of meat you want to eat: beef or pork or chichen???");
		String meatKind ="hello"; meatKind = ComprehensiveExperimentClient.scanner.nextLine(); 
		MeatFactory meatFactory=null;
		switch(meatKind) {
		case "beef": meatFactory=new BeefMeatFactory();System.out.println("OK");break;
		case "pork": meatFactory=new PorkMeatFactory();System.out.println("OK");break;
		case "chicken": meatFactory=new ChickenMeatFactory();System.out.println("OK");break;
		default:System.out.println("sorry, your input is not correct");
		}

}
	public void abstractFactory() {
		System.out.println("Please select which brand you want to buy: Wens, Tianbang or Aonong???");
		String brand = ComprehensiveExperimentClient.scanner.nextLine();
		AbstractFactory factory = null; 
		switch(brand){
		case "Wens": factory=new WensFactory();break;
		case "Tianbang": factory=new TianbangFactory();break;
		case "Aonong": factory=new AonongFactory();break;
		default:System.out.println("sorry, your input is not correct");
		
		}
		System.out.println("Please select which meat you want to buy: pork, beef or chicken???");
		String meatName = null;
		meatName = ComprehensiveExperimentClient.scanner.nextLine();
		Meat meatInstance = null;
		switch(meatName){
		case "pork": meatInstance = factory.createPork();break;		
		case "beef": meatInstance = factory.createBeef();break;	
		case "chicken": meatInstance = factory.createChicken();break;	
		default:System.out.println("sorry, your input is not correct");
		}  
		if(meatInstance!=null) {
			meatInstance.cook();
		}

	}
	public void adapter() {//实验4适配器
		Stage stage = new Stage();
        try{
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass().getResource("AdapterClient.fxml"));
            Parent root = (Parent)loader.load();
            Scene scene = new Scene(root);
            stage.setTitle("Adapter");
            stage.setScene(scene);
            stage.show();
            Students.stuList=new ArrayList<AdapterStudent>();
        }catch (Exception e){
            e.printStackTrace();
        }
	}
	public void consistentComposite() {//一致性组合
		ConsistentCompositeClient consistentCompositeClient = new ConsistentCompositeClient();
		consistentCompositeClient.select();
	}
	public void safeComposite() {//安全组合
		warn.setText("正在");
		SafeCompositeClient safeCompositeClient = new SafeCompositeClient();
		safeCompositeClient.select();
	}
	public void hibernate() {//实验六	
		HibernateClientHibernateDao.show();	
	}
    public void useOfSpring() {//实验七
    	ApplicationContext ac = Spring03SingletonApplicationContextClient.getApplicationContext();
		IocStudent zhangsan=(IocStudent) ac.getBean("zhangsan");
		System.out.println(zhangsan.getName()+"的毕业设计指导导师是："+zhangsan.getTutor().getName());
		warn.setText("请选择");
    }

}
